import Ajax from './customajax'

export default {
    getGraphConfig(id) {
        const url = '/dirms/dev/graphs/getByNo/' + id;
        return Ajax.query(url);
    },
    viewData(key, params) {
        if (!params) {
            params = {};
        }
        return Ajax.call({
            url: '/dirms/dev/dataSource/viewData?key=' + key,
            method: "post",
            contentType: "application/json",
            dataType: "json",
            data: JSON.stringify(params)
        });
    },
    listDs() {
        const url = '/dirms/dev/dataSource/all';
        return Ajax.query(url);
    },
    testDs(formData) {
        return Ajax.call({
            method: 'post',
            data: JSON.stringify(formData),
            contentType: "application/json; charset=UTF-8",
            url: '/dirms/dev/dataSource/connect'
        });
    },
    deleteDs(id) {
        const url = '/dirms/dev/dataSource/' + id;
        return Ajax.delete(url);
    },
    saveDs(formData) {
        return Ajax.call({
            url: '/dirms/dev/dataSource/save',
            method: "post",
            contentType: "application/json",
            dataType: "json",
            data: JSON.stringify(formData)
        });
    },
    listGraphs(type) {
        const url = '/dirms/dev/graphs/listGraphByType?grsType=' + type;
        return Ajax.query(url);
    },
    saveGraphs(formData) {
        return Ajax.call({
            url: '/dirms/dev/graphs/save',
            method: "post",
            contentType: "application/json",
            dataType: "json",
            data: JSON.stringify(formData)
        });
    },
    deleteGraphs(id) {
        const url = '/dirms/dev/graphs/' + id;
        return Ajax.delete(url);
    },
    sendToMenu(formData, displayPath, parentMenuName) {
        return Ajax.call({
            url: '/dirms/dev/graphs/sendToMenu/' + encodeURIComponent(encodeURIComponent(displayPath)) + '/' + encodeURIComponent(encodeURIComponent(parentMenuName)),
            method: "post",
            contentType: "application/json",
            dataType: "json",
            data: JSON.stringify(formData)
        });
    },
    itemTrend(itemid, startTimeStamp, endTimeStamp) {
        return Ajax.call({
            url: '/dirms/monitor/history/get/' + itemid + '/' + startTimeStamp + '/' + endTimeStamp,
            method: "get",
            contentType: "application/json"
        });
    }
}